package cn.wolfcode.rbac.controller;

import cn.wolfcode.rbac.annotation.RequiredPermission;
import cn.wolfcode.rbac.config.QueryObject;
import cn.wolfcode.rbac.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author Lu.F
 * @version 1.0
 * @Description TODO
 * @date 2022/5/21 10:29
 */
@Controller
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    //分页操作与查询操作是一体的
    @RequestMapping("/list")
    public String list(Model model, QueryObject qo){
        //List<Permission> permissions = permissionService.listAll();
        model.addAttribute("pageInfo",permissionService.selectPage(qo));
        return "permission/list";
    }

    /**
     * 根据主键删除
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    @RequiredPermission({"权限加载","permission:delete"})
    public String delete(Long id){
        if (id != null){
            permissionService.deleteByPrimaryKey(id);
        }
        return "redirect:/permission/list";
    }

    /**
     * 重载
     * @return
     */
    @RequestMapping("/reload")
    @RequiredPermission({"权限加载","permission:reload"})
    public String reload(){
        permissionService.reload();
        return "redirect:/permission/list";
    }
}
